import Vue from 'vue'
import Vuex from 'vuex'
import vuexAlong  from 'vuex-along'

Vue.use(Vuex)

vuexAlong.onlySession(true)

const store = new Vuex.Store({
  state: {
    // domain: 'http://demo.bjyoumeng.cn/',
    domain: '/',
    // domain: 'https://c.yidiangaoren.com/',
    token: '',
    userId: '',
    masterId: '',
    isMaster: false,

    homeLogo: 'logo',

    userPhone: '',
    verifyPhone: false,

    remind: true,
    remindTime: 15,

    test: '1111',
    test01: {
      name: 'Wise Wrong'
    },
    test02: {
      tell: '12312345678'
    },
    todos: [{
        id: 1,
        text: '...',
        done: true
      },
      {
        id: 2,
        text: '...',
        done: false
      }
    ],
  },
  getters: {
    doneTodos: state => {
      return state.todos.filter(todo => todo.done)
    }
  },
  actions: {
    saveForm(context) {
      axios({
        method: 'post',
        url: '/user',
        data: context.state.test02
      })
    }
  },
  mutations: {
    login(state, payload) {
      state.token = payload.token;
      state.userId = payload.userId;

      state.homeLogo = payload.homeLogo

      state.masterId = payload.masterId;
      state.isMaster = payload.masterId ? true : false;

      state.userPhone = payload.userPhone;
      state.verifyPhone = false;
    },
    logout(state) {
      state.token = '';
      state.userId = '';
      state.userPhone = '';
      state.masterId = '';
    },
    switchover(state, payload) {
      state.masterId = payload.masterId;
      state.isMaster = payload.masterId ? true : false;
    },
    showPhone(state, bool) {
      state.verifyPhone = bool;
    },
    addPhone(state, phone) {
      state.userPhone = phone;
    },
    remindchu(state, bool) {
      state.remind = bool
    }
  },
  plugins: [vuexAlong],
})

export default store
